package peace.transport.xmlrpc.type
{
import peace.transport.xmlrpc.Xmlrpc;

public dynamic class XmlrpcArray extends Array
{
	public function get xml ():XML
	{
		var xml:XML = 
			<array>
			  <data/>
			</array>
			
		for each (var v:* in this)
		{
			xml.data.* += <value>{Xmlrpc.encodeValue(v)}</value>;
		}
		
		return xml;
	}
	
	public function XmlrpcArray (array:Array = null)
	{
		super();
		if (array)
		{
			for each (var v:* in array)
			{
				push(v);
			}
		}
	}
	/**
	 * @param xml
	 * @return 
	 */	
	public static function parse (xml:XML):XmlrpcArray
	{
		var arr:XmlrpcArray = new XmlrpcArray();
		for each (var node:XML in xml.data.value.*)
		{
			arr.push(Xmlrpc.decodeValue(node));
		}
		return arr;
	}

}
}